package org.example.hansp.reflection.reflection02;

import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo2 {
    public static void main(String[] args) throws Exception {
        //1.使用properties类，读写配置文件
        Properties prop = new Properties();
        prop.load(new FileInputStream("src\\main\\java\\org\\example\\hansp\\reflection\\reflection02\\re.properties"));
        String classfullpath = prop.getProperty("classfullpath").toString();
        String methodName = prop.getProperty("method").toString();
        System.out.println("classfullpath: " + classfullpath);
        System.out.println("method: " + methodName);

        Class cls=Class.forName(classfullpath);
        Object o = cls.newInstance();
        Method m=cls.getMethod(methodName);
        m.invoke(o);

        Field ageFiled = cls.getField("age");
        System.out.println(ageFiled.get(o));

        Constructor constructor=cls.getConstructor();
        System.out.println(constructor);
        Constructor constructor1 = cls.getConstructor(String.class);
        System.out.println(constructor1);
    }
}
